﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using AjaxControlToolkit;

namespace CTEA_INDIA
{
    public partial class ProductDetails1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            BAL.conn.connectionString = ConfigurationManager.ConnectionStrings["CTEA"].ConnectionString;
            if (Session["UserID"] == null)
            {
                Response.Redirect("Default.aspx");
            }


            for (int i = 1; i <= 12; i++)
            {
                cmbEdtHr.Items.Add(i.ToString());

            }

            cmbEdtMin.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbEdtMin.Items.Add(i.ToString());
            }



            for (int i = 1; i <= 12; i++)
            {
                cmbDelHr.Items.Add(i.ToString());

            }

            cmbDelMin.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbDelMin.Items.Add(i.ToString());
            }

            if (!IsPostBack)
            {
                BAL.Customers.PopulateLoc(ref ddlLoc);
                PopulateProductDetail();

               
            }


            for (int i = 1; i <= 12; i++)
            {
                cmbEdtHr1.Items.Add(i.ToString());

            }

            cmbEdtMin1.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbEdtMin1.Items.Add(i.ToString());
            }





            if (!IsPostBack)
            {
                BAL.Customers.PopulateLoc(ref ddlLoc1);
                PopulateProductDetail1();


            }
            for (int i = 1; i <= 12; i++)
            {
                cmbEdtHrpo.Items.Add(i.ToString());

            }

            cmbEdtMinpo.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbEdtMinpo.Items.Add(i.ToString());
            }



            for (int i = 1; i <= 12; i++)
            {
                cmbDelHrpo.Items.Add(i.ToString());

            }

            cmbDelMinpo.Items.Add("00");

            for (int i = 1; i <= 59; i++)
            {
                cmbDelMinpo.Items.Add(i.ToString());
            }

            BAL.Customers.PopulateLocation(ref ddlLocationpo);
            BAL.Customers.PopulateLocation(ref cmbEdtLocationpo);
            populateAudtionpo();

        }
        
        public void clear()
        {
            txtProductName.Text = "";

            txtDirectorName.Text = "";
            cmbTypesOfFilms.SelectedIndex = 0;
            txtAudDate.Text = "";
            cmbDelHr.SelectedIndex = 0;
            cmbDelMin.SelectedIndex = 0;
            cmbDelAmPm.SelectedIndex = 0;
            txtRefComName.Text = "";
            txtRefContact.Text = "";
            cmbReqFor.SelectedIndex = 0;
            txtAgeFrom.Text = "";
            txtAgeTo.Text = "";
            cmbTypeOfArtist.SelectedIndex = 0;
        }

        private void PopulateProductDetail()
        {
            DataSet ds = BAL.Customers.ViewProductDetail();
            gdProductDetail.DataSource = ds;
            gdProductDetail.DataBind();
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            string ProductName = txtProductName.Text;
            string ProducerName = "Abc";
            string DirectorName = txtDirectorName.Text;
            string TypeOfFilm = cmbTypesOfFilms.Text;
            string AudDate = txtAudDate.Text;
            string AudHr = cmbDelHr.Text;
            string AudMin = cmbDelMin.Text;
            string AudAmPm = cmbDelAmPm.Text;
            string RefName = txtRefComName.Text;
            string RefContact = txtRefContact.Text;
            string ReqFor = cmbReqFor.Text;
            string AgeFrm = txtAgeFrom.Text;
            string AgeTo = txtAgeTo.Text;
            string TypeOfArtist = cmbTypeOfArtist.Text;

            spnMsg.Visible = true;
            spnText.InnerHtml = "Your details have been submitted.";

            BAL.Customers.InsertProduct(ProductName, ProducerName, DirectorName, TypeOfFilm, AudDate, AudHr, AudMin, AudAmPm,
                RefName, RefContact, ReqFor, AgeFrm, AgeTo, TypeOfArtist);
            clear();



        }

        protected void lnkView_Click(object sender, EventArgs e)
        {
            LinkButton lnkVw = sender as LinkButton;

            //  lnkView_ModalPopupExtender.TargetControlID = "lnkVw";

            GridViewRow row = (GridViewRow)lnkVw.Parent.Parent;
            int ProductId = Convert.ToInt32(gdProductDetail.DataKeys[row.RowIndex]["ProductID"]);
            string[] Details = BAL.Customers.GetProductByID(ProductId);
            lblProductName.Text = Details[1];
            lblProducterName.Text = Details[2];
            lblDirectorName.Text = Details[3];
            lblTypesOFFilms.Text = Details[4];
            lblAUdDate.Text = DateTime.Parse(Details[5]).ToShortDateString();
            lblAudTIme.Text = Details[6] + ":" + Details[7] + ":" + Details[8];
            lblReqFor.Text = Details[11];
            lblAge.Text = "From " + Details[12] + " to " + Details[13];
            lblTypeOfArtist.Text = Details[14];


            lblRefName.Text = Details[9];
            lblRefContact.Text = Details[10];

            lnkView_ModalPopupExtender.Show();

            // tblrunngAudi.Visible = true;


        }


        protected void btnSearch_Click(object sender, EventArgs e)
        {

            int Type = Convert.ToInt32(ddlSearch.SelectedValue);
            string SearchTxt;
            
            if (Type == 0)
            {
                PopulateProductDetail();
            }
            else if (Type == 1)
            {
                SearchTxt = txtSearchText.Text;
                DataSet ds = BAL.Customers.SearchAudition(Type, SearchTxt);
                gdProductDetail.DataSource = ds;
                gdProductDetail.DataBind();
               
            }
            else if (Type == 2)
            {
                SearchTxt = ddlTypeofFilm.Text;
                DataSet ds = BAL.Customers.SearchAudition(Type, SearchTxt);
                gdProductDetail.DataSource = ds;
                gdProductDetail.DataBind();
            }
            //else if (Type == '3')
            //{
            //    SearchTxt = ddlLoc.Text;
            //}

            
           
        }

        protected void lnkEdit_Click(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(gdProductDetail.DataKeys[row.RowIndex]["ProductID"]);
            string[] Details = BAL.Customers.GetProductByID(Cid);
            txtEdtProdName.Text = Details[1];
            txtEdtProdTitle.Text = Details[2];
            txtEdtDirectorName.Text = Details[3];

            ViewState["ProductId"] = Cid;
            string[] stsArr = { "Serial", "Films", "Adfilms", "Documentary", "Online Film", "Pilot", "Budget" };

            for (int i = 0; i <= 6; i++)
            {
                if (Details[4].ToString().Equals(stsArr[i]))
                {
                    cmbEdtTypesOfFilms.SelectedIndex = i + 1;
                    break;
                }
            }

            for (int i = 1; i <= 12; i++)
            {
                if (Details[6].ToString().Equals(i.ToString()))
                {
                    cmbEdtHr.SelectedIndex = i - 1;
                    break;
                }
            }

            if (Details[7].ToString().Equals("0"))
            {
                cmbEdtMin.SelectedIndex = 0;
            }
            else
            {
                for (int i = 1; i <= 59; i++)
                {
                    if (Details[7].ToString().Equals(i.ToString()))
                    {
                        cmbEdtMin.SelectedIndex = i;
                        break;
                    }
                }
            }


            if (Details[8].ToString().Equals("Am"))
            {
                cmbEdtAmPm.SelectedIndex = 0;

            }
            else if (Details[8].ToString().Equals("Pm"))
            {
                cmbEdtAmPm.SelectedIndex = 1;

            }


            string[] reqArr = { "Male", "Female", "child" };

            for (int i = 0; i <= 2; i++)
            {
                if (Details[11].ToString().Equals(reqArr[i]))
                {
                    cmbEdtReqFor.SelectedIndex = i + 1;
                    break;
                }
            }


            string[] artTypeArr = { "Celebrity", "Aspiring", "Model" };

            for (int i = 0; i <= 2; i++)
            {
                if (Details[14].ToString().Equals(artTypeArr[i]))
                {
                    cmbEdtArtistType.SelectedIndex = i + 1;
                    break;
                }
            }


            txtEdtAudDate.Text = DateTime.Parse(Details[5].ToString()).ToShortDateString();

            txtEdtAgeFrom.Text = Details[12];
            txtEdtAgeTo.Text = Details[13];
            txtEdtRefComName.Text = Details[9];
            txtEdtRefContact.Text = Details[10];



            LnkEditPopUp.Show();


        }

        protected void lnkDelete_Click(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(gdProductDetail.DataKeys[row.RowIndex]["ProductID"]);
            BAL.Customers.DeleteProductById(Cid);
            PopulateProductDetail();
        }

        protected void update(object sender, EventArgs e)
        {
            string ProductId = ViewState["ProductId"].ToString();
            string ProductName = txtEdtProdName.Text;
            string ProducerName = txtEdtProdTitle.Text;
            string DirectorName = txtEdtDirectorName.Text;
            string TypeOfFilm = cmbEdtTypesOfFilms.Text;
            string AudDate = txtEdtAudDate.Text;
            string AudHr = cmbEdtHr.Text;
            string AudMin = cmbEdtMin.Text;
            string AudAmPm = cmbEdtAmPm.Text;
            string RefName = txtEdtRefComName.Text;
            string RefContact = txtEdtRefContact.Text;
            string ReqFor = cmbEdtReqFor.Text;
            string AgeFrm = txtEdtAgeFrom.Text;
            string AgeTo = txtEdtAgeTo.Text;
            string TypeOfArtist = cmbEdtArtistType.Text;

            BAL.Customers.Update_Add_Audition(ProductId, ProductName, ProducerName, DirectorName, TypeOfFilm, AudDate, AudHr, AudMin
                , AudAmPm, RefName, RefContact, ReqFor, AgeFrm, AgeTo, TypeOfArtist);

            PopulateProductDetail();
        }

        ///////////////////////////////////////////////////////////////

        private void PopulateProductDetail1()
        {
            DataSet ds = BAL.Customers.ViewProductDetailUpcomming();
            gdProductDetail1.DataSource = ds;
            gdProductDetail1.DataBind();
        }


        protected void lnkView_Click1(object sender, EventArgs e)
        {
            LinkButton lnkVw = sender as LinkButton;

            //  lnkView_ModalPopupExtender.TargetControlID = "lnkVw";

            GridViewRow row = (GridViewRow)lnkVw.Parent.Parent;
            int ProductId = Convert.ToInt32(gdProductDetail1.DataKeys[row.RowIndex]["ProductID"]);
            string[] Details = BAL.Customers.GetProductByID(ProductId);
            lblProductName1.Text = Details[1];
            lblProducterName1.Text = Details[2];
            lblDirectorName1.Text = Details[3];
            lblTypesOFFilms1.Text = Details[4];
            lblAUdDate1.Text = DateTime.Parse(Details[5]).ToShortDateString();
            lblAudTIme1.Text = Details[6] + ":" + Details[7] + ":" + Details[8];
            lblReqFor1.Text = Details[11];
            lblAge1.Text = "From " + Details[12] + " to " + Details[13];
            lblTypeOfArtist1.Text = Details[14];


            lblRefName1.Text = Details[9];
            lblRefContact1.Text = Details[10];

            lnkView1_ModalPopupExtender.Show();

            // tblrunngAudi.Visible = true;


        }


        protected void btnSearch_Click1(object sender, EventArgs e)
        {

            int Type = Convert.ToInt32(ddlSearch1.SelectedValue);
            string SearchTxt;

            if (Type == 0)
            {
                PopulateProductDetail1();
            }
            else if (Type == 1)
            {
                SearchTxt = txtSearchText1.Text;
                DataSet ds = BAL.Customers.SearchAudition(Type, SearchTxt);
                gdProductDetail1.DataSource = ds;
                gdProductDetail1.DataBind();

            }
            else if (Type == 2)
            {
                SearchTxt = ddlTypeofFilm1.Text;
                DataSet ds = BAL.Customers.SearchAudition(Type, SearchTxt);
                gdProductDetail1.DataSource = ds;
                gdProductDetail1.DataBind();
            }
            //else if (Type == '3')
            //{
            //    SearchTxt = ddlLoc.Text;
            //}



        }

        protected void lnkEdit_Click1(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(gdProductDetail1.DataKeys[row.RowIndex]["ProductID"]);
            string[] Details = BAL.Customers.GetProductByID(Cid);
            txtEdtProdName1.Text = Details[1];
            txtEdtProdTitle1.Text = Details[2];
            txtEdtDirectorName1.Text = Details[3];

            ViewState["ProductId"] = Cid;
            string[] stsArr = { "Serial", "Films", "Adfilms", "Documentary", "Online Film", "Pilot", "Budget" };

            for (int i = 0; i <= 6; i++)
            {
                if (Details[4].ToString().Equals(stsArr[i]))
                {
                    cmbEdtTypesOfFilms1.SelectedIndex = i + 1;
                    break;
                }
            }

            for (int i = 1; i <= 12; i++)
            {
                if (Details[6].ToString().Equals(i.ToString()))
                {
                    cmbEdtHr1.SelectedIndex = i - 1;
                    break;
                }
            }

            if (Details[7].ToString().Equals("0"))
            {
                cmbEdtMin1.SelectedIndex = 0;
            }
            else
            {
                for (int i = 1; i <= 59; i++)
                {
                    if (Details[7].ToString().Equals(i.ToString()))
                    {
                        cmbEdtMin1.SelectedIndex = i;
                        break;
                    }
                }
            }


            if (Details[8].ToString().Equals("Am"))
            {
                cmbEdtAmPm1.SelectedIndex = 0;

            }
            else if (Details[8].ToString().Equals("Pm"))
            {
                cmbEdtAmPm1.SelectedIndex = 1;

            }


            string[] reqArr = { "Male", "Female", "child" };

            for (int i = 0; i <= 2; i++)
            {
                if (Details[11].ToString().Equals(reqArr[i]))
                {
                    cmbEdtReqFor1.SelectedIndex = i + 1;
                    break;
                }
            }


            string[] artTypeArr = { "Celebrity", "Aspiring", "Model" };

            for (int i = 0; i <= 2; i++)
            {
                if (Details[14].ToString().Equals(artTypeArr[i]))
                {
                    cmbEdtArtistType1.SelectedIndex = i + 1;
                    break;
                }
            }


            txtEdtAudDate1.Text = DateTime.Parse(Details[5].ToString()).ToShortDateString();

            txtEdtAgeFrom1.Text = Details[12];
            txtEdtAgeTo1.Text = Details[13];
            txtEdtRefComName1.Text = Details[9];
            txtEdtRefContact1.Text = Details[10];



            LnkEditPopUp1.Show();


        }

        protected void lnkDelete_Click1(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(gdProductDetail1.DataKeys[row.RowIndex]["ProductID"]);
            BAL.Customers.DeleteProductById(Cid);
            PopulateProductDetail1();
        }

        protected void update1(object sender, EventArgs e)
        {
            string ProductId = ViewState["ProductId"].ToString();
            string ProductName = txtEdtProdName1.Text;
            string ProducerName = txtEdtProdTitle1.Text;
            string DirectorName = txtEdtDirectorName1.Text;
            string TypeOfFilm = cmbEdtTypesOfFilms1.Text;
            string AudDate = txtEdtAudDate1.Text;
            string AudHr = cmbEdtHr1.Text;
            string AudMin = cmbEdtMin1.Text;
            string AudAmPm = cmbEdtAmPm1.Text;
            string RefName = txtEdtRefComName1.Text;
            string RefContact = txtEdtRefContact1.Text;
            string ReqFor = cmbEdtReqFor1.Text;
            string AgeFrm = txtEdtAgeFrom1.Text;
            string AgeTo = txtEdtAgeTo1.Text;
            string TypeOfArtist = cmbEdtArtistType1.Text;

            BAL.Customers.Update_Add_Audition(ProductId, ProductName, ProducerName, DirectorName, TypeOfFilm, AudDate, AudHr, AudMin
                , AudAmPm, RefName, RefContact, ReqFor, AgeFrm, AgeTo, TypeOfArtist);

            PopulateProductDetail1();
        }
        


        public void clearpo()
        {

            txtTitleOfProductionpo.Text = "";
            txtCastingDirectorpo.Text = "";
            txtContactNopo.Text = "";
            txtAudtionDatepo.Text = "";
            ddltypeOfProductionpo.SelectedIndex = 0;
            txtProductionNamepo.Text = "";


        }


        public void populateAudtionpo()
        {

            DataSet ds = BAL.Customers.ViewAllAudtionSheetDetails();
            grdAudtionSheetpo.DataSource = ds;
            grdAudtionSheetpo.DataBind();

        }

        protected void ShowInsertAritstpo(object sender, CommandEventArgs e)
        {

            LinkButton lnkAudiID = (LinkButton)sender;
            GridViewRow row = (GridViewRow)lnkAudiID.Parent.Parent;
            GridViewRow grdAudiSheet = (GridViewRow)(lnkAudiID.Parent.Parent);
            int AudiID = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);



            Response.Redirect("Audition_Artist.aspx?AudiID=" + AudiID);


        }


        protected void btnSearch_Clickpo(object sender, EventArgs e)
        {

        }

        protected void lnkEdit_Clickpo(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
            string[] Details = BAL.Customers.GetAuditionSheetById(Cid);
            ViewState["AudtionID"] = Cid.ToString();

            txtEdtAudDatepo.Text = DateTime.Parse(Details[1]).ToShortDateString();
            txtEdtProdNamepo.Text = Details[2];
            txtEdtTOPpo.Text = Details[3];
            cmbEdtTypeOPpo.SelectedValue = Details[4];
            txtEdtCDNpo.Text = Details[5];
            txtEdtContactpo.Text = Details[6];
            cmbEdtLocationpo.SelectedValue = Details[7];


            cmbEdtHrpo.SelectedValue = Details[8];
            cmbEdtMinpo.SelectedValue = Details[9];
            cmbEdtAmPmpo.SelectedValue = Details[10];

            LnkEditPopUppo.Show();
        }

        protected void lnkDelete_Clickpo(object sender, EventArgs e)
        {
            LinkButton lnkEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkEdit.Parent.Parent;

            int Cid = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
            BAL.Customers.DeleteAuditionSheetDetailById(Cid);
            populateAudtionpo();
        }

        protected void updatepo(object sender, EventArgs e)
        {


            DateTime AuditoinDate = Convert.ToDateTime(txtEdtAudDatepo.Text);
            string ProductionName = txtEdtProdNamepo.Text;
            string TitleProduction = txtEdtTOPpo.Text;
            string TypeProduction = cmbEdtTypeOPpo.Text;
            string CastingDirectName = txtEdtCDNpo.Text;
            string ContNo = txtEdtContactpo.Text;
            string Address = cmbEdtLocationpo.SelectedValue;
            string hr = cmbEdtHrpo.Text;
            string min = cmbEdtMinpo.Text;
            string ampm = cmbEdtAmPmpo.Text;

            string AudtionID = ViewState["AudtionID"].ToString();
            BAL.Customers.UpdateAuditionSheetDetails(AudtionID, AuditoinDate, ProductionName, TitleProduction, TypeProduction, CastingDirectName, ContNo, Address, hr, min, ampm);

            populateAudtionpo();

        }

        protected void lnkView_Clickpo(object sender, EventArgs e)
        {
            LinkButton lnkVw = sender as LinkButton;
            GridViewRow row = (GridViewRow)lnkVw.Parent.Parent;
            // int locationID = Convert.ToInt32(ddlLocation.SelectedValue);
            int Cid = Convert.ToInt32(grdAudtionSheetpo.DataKeys[row.RowIndex]["AudtionID"]);
            string[] Details = BAL.Customers.GetAuditionSheetById(Cid);

            lblDateOfAudpo.Text = Details[1];
            lblProdNamepo.Text = Details[2];
            lblTOPpo.Text = Details[3];
            lblTypeOPpo.Text = Details[4];
            lblCDNpo.Text = Details[5];
            lblContactpo.Text = Details[6];
            lblLocationpo.Text = Details[7];
            lblViewTimepo.Text = Details[8] + ":" + Details[9] + ":" + Details[10];
            lnkView_ModalPopupExtenderpo.Show();

            //document.getElementById("totalDaystd").innerHTML = "<asp:TextBox ID=\"txtDaysText\" runat=\"server\" ReadOnly=\"True\" Text=\""+ days +"\"></asp:TextBox>";

        }

        protected void btnSubmitpo_Click(object sender, EventArgs e)
        {
            DateTime AuditoinDate = Convert.ToDateTime(txtAudtionDatepo.Text);
            string ProductionName = txtProductionNamepo.Text;
            string TitleProduction = txtTitleOfProductionpo.Text;
            string TypeProduction = ddltypeOfProductionpo.Text;
            string CastingDirectName = txtCastingDirectorpo.Text;
            string ContNo = txtContactNopo.Text;
            string Address = ddlLocationpo.Text;
            string hr = cmbDelHrpo.Text;
            string min = cmbDelMinpo.Text;
            string ampm = cmbDelAmPmpo.Text;
            BAL.Customers.AuditionSheetDetails(AuditoinDate, ProductionName, TitleProduction, TypeProduction, CastingDirectName, ContNo, Address, hr, min, ampm);



            populateAudtionpo();
            txtTitleOfProductionpo.Text = "";
            txtCastingDirectorpo.Text = "";
            txtContactNopo.Text = "";
            txtAudtionDatepo.Text = "";
            ddltypeOfProductionpo.SelectedIndex = 0;
            txtProductionNamepo.Text = "";
        }

      

    }
}